001    package videoautomat.contentcreator;
002    import java.awt.Color;
003    import java.awt.GridLayout;
004    
005    import javax.swing.Box;
006    import javax.swing.BoxLayout;
007    import javax.swing.JComponent;
008    import javax.swing.JLabel;
009    import javax.swing.JPanel;
010    import javax.swing.JPasswordField;
011    import javax.swing.JTextArea;
012    import javax.swing.JTextField;
013    
014    import sale.FormSheet;
015    import sale.FormSheetContentCreator;
016    import videoautomat.contentcreator.stdactions.RollBackAction;
017    import videoautomat.contentcreator.stdactions.TransitWithAction;
018    import videoautomat.transition.RegisterOKTransition;
019    
020    /**
021     * Content creator of the register process. Contains methods to set and add data 
022     * independly from the gui part.
023     *
024     * @author Tobias Ruch
025     */
026    public class RegisterContentCreator extends FormSheetContentCreator {   
027    
028       /** Textarea for the error message */
029       private JTextArea errorMessage;
030       /** Label with the initial massage */
031       private JLabel message;
032       /** Textfield for the user name */
033       private JTextField userName;
034       /** PasswordField for the 1st password */
035       private JPasswordField password;
036       /** PasswordField for the 2nd password */
037       private JPasswordField confirmedPassword;   
038       /**
039        * Creates a new content creator with an initial message
040        * @param message - initial message
041        */
042       public RegisterContentCreator(String message){
043          
044          //initialize components
045          errorMessage      = new JTextArea();
046          this.message      = new JLabel();
047          userName          = new JTextField();
048          password          = new JPasswordField();
049          confirmedPassword = new JPasswordField();      
050          //set initial values
051          this.message.setText(message);
052          errorMessage.setForeground(Color.RED);
053          errorMessage.setBackground(this.message.getBackground());
054          //errorMessage.setEnabled(false);
055          errorMessage.setEditable(false);
056       }   
057       
058       /**
059        * Method will be called from the FormSheet to which this ContentCreator is added.
060        * So the Attribut fs will be this FormSheet.
061        * You have to bild the content of your formsheet in this method
062        * @param fs - FormSheet to which this ContentCreator was added.
063        */
064       protected void createFormSheetContent(FormSheet fs) {    
065          fs.removeAllButtons();
066          
067          
068          //settings to Panels
069          JComponent component    = new JPanel();
070          JComponent outerPanel   = new JPanel(); // a Panal with flow layout for optimal size of added components
071          JComponent messagePanel = new JPanel(new GridLayout(0,1));
072          JComponent inputPanel   = new JPanel(new GridLayout(0,2,5,15));      
073          component.setLayout(new BoxLayout(component, BoxLayout.Y_AXIS)); 
074          //?----outerPanel-------?
075          //|?---component-------?|
076          //||?-----------------?||
077          //|||    message      |||
078          //||?-----------------?||
079          //||?-----------------?||
080          //|||    input        |||
081          //||?-----------------?||
082          //|?-------------------?|
083          //?---------------------?
084          
085          
086          messagePanel.add(errorMessage);
087          messagePanel.add(message);
088          
089          inputPanel.add(new JLabel("User Name"));
090          inputPanel.add(userName);
091          inputPanel.add(new JLabel("Password"));
092          inputPanel.add(password);
093          inputPanel.add(new JLabel("Confirm Password"));
094          inputPanel.add(confirmedPassword);
095          
096          component.add(messagePanel);
097          component.add(Box.createVerticalStrut(30));
098          component.add(inputPanel);
099          
100          outerPanel.add(component);
101          // set Buttons; using standard action to set transition classes
102          fs.addButton("OK", 1, new TransitWithAction(new RegisterOKTransition(this)));
103          fs.addButton("Cancel", 2, new RollBackAction());
104          
105          fs.setComponent(outerPanel);      
106       }   
107    
108       
109       /**
110        * Returns the value of the username.
111        * @return - the username
112        */
113       public String getUserName(){
114          return userName.getText();
115       }
116       
117       /**
118        * Returns the value of the password.
119        * @return - the value of the password as an char array
120        */
121       public char[] getPassword(){
122          return password.getPassword();
123       }
124       
125       /**
126        * Returns the value of the confirmed password.
127        * @return - the value of the password as an char array
128        */
129       public char[] getConfirmedPassword(){
130          return confirmedPassword.getPassword();
131       }
132       
133       /**
134        * Sets the value of the username
135        * @param userName - value of the username
136        */
137       public void setUserName(String userName){
138          this.userName.setText(userName);
139       }
140       
141       /**
142        * Sets the error message to this formsheet.
143        * @param message - an error massage.
144        */
145       public void setErrorMessage(String message){
146          errorMessage.setText(message);
147       }   
148       
149    }